using System;
using NUnit.Framework;
using RMH.Entities;
using RMH.Services;
using RMH.Web.Controllers;
using RMH.Web.Models.Binders;

namespace RMH.UnitTests.Web.Binders
{
    [TestFixture]
    public class StayBinder_when_binding_an_existing_stay : base_binding_test<StayController>
    {
        private Stay stay;
        private DateTime checkinDate = DateTime.Today.AddDays(5);
        private DateTime checkoutDate = DateTime.Today.AddDays(35);
        private string hospitalPhone = "232-232-2323";
        private string medicaidNumber = "asda";
        private DateTime PreauthorizationApprovedDate = DateTime.Today.AddDays(23);
        string socialWorkerName = "Miss Judy";
        private string hospitalUnit = "ASDASDADASD";
        private string hospitalRoom = "23232";
        private int patientId = 23;
        private Patient patient = new Patient {Id = 23};
        private Room room = new Room {Id = 2};
        DateTime paymentBillingDate = new DateTime(2002, 2, 2);
        private string paymentCheckNumber = "@SALDKS";
        private PaymentMethod paymentMethod = PaymentMethod.MasterCard;
        private DateTime paymentReceivedDateTime = DateTime.Today.AddDays(3);
        private PaymentType paymentType = PaymentType.SelfPay;
        public override void establish_context()
        {
            

            form.Add("CheckinDate", checkinDate.ToString());
            form.Add("CheckoutDate", checkoutDate.ToString());
            form.Add("HospitalPhoneNumber", hospitalPhone);
            form.Add("MedicaidNumber", medicaidNumber);
            form.Add("PreauthorizationApprovedDate", PreauthorizationApprovedDate.ToString());
            form.Add("PreauthorizationSentDate", checkinDate.ToString());
            form.Add("SocialWorkerName", socialWorkerName);
            form.Add("HospitalUnit", hospitalUnit);
            form.Add("PatientId", patientId.ToString());
            form.Add("OccupancyType", OccupancyType.ClosedRepairs.ToInt().ToString());
            form.Add("HospitalRoomNumber", hospitalRoom);
            form.Add("roomId", room.Id.ToString());
            
            form.Add("Payment.Amount", paymentAmount.ToString());            
            form.Add("Payment.BillingDate", paymentBillingDate.ToString());
            form.Add("Payment.CheckNumber", paymentCheckNumber);
            form.Add("Payment.Method", paymentMethod.ToInt().ToString());
            form.Add("Payment.ReceivedDate", paymentReceivedDateTime.ToString());
            form.Add("Payment.Type", paymentType.ToInt().ToString());

            Mock<IPatientService>()
                .Setup(s => s.Get(patientId))
                .Returns(patient);

            Mock<IRoomService>()
                .Setup(s => s.Get(room.Id))
                .Returns(room);

            context.HttpRequest.Setup(r => r.Form).Returns(form);
        }

        public override void because()
        {
            var binder = Create<StayBinder>();
            stay = (Stay)getBindingResult(binder);
        }


        [Test]
        public void sets_properties()
        {
            stay.CheckinDate.ShouldEqual(checkinDate);
            stay.CheckoutDate.ShouldEqual(checkoutDate);
            stay.HospitalPhoneNumber.ShouldEqual(hospitalPhone);
            stay.MedicaidNumber.ShouldEqual(medicaidNumber);
            stay.PreauthorizationApprovedDate.ShouldEqual(PreauthorizationApprovedDate);
            stay.PreauthorizationSentDate.ShouldEqual(checkinDate);            
            stay.SocialWorkerName.ShouldEqual(socialWorkerName);
            stay.HospitalUnit.ShouldEqual(hospitalUnit);
            stay.Type.ShouldEqual(OccupancyType.ClosedRepairs);
            stay.HospitalRoomNumber.ShouldEqual(hospitalRoom);
        }

        [Test]
        public void sets_county()
        {
            Assert.Fail("Need To Test");
        }

        [Test]
        public void sets_patient()
        {
            stay.Patient.ShouldEqual(patient);
        }

        [Test]
        public void sets_room()
        {
            stay.Room.ShouldEqual(room);
        }

        private double paymentAmount = 23.23;
        

        [Test]
        public void sets_payment_fields()
        {
            stay.Payment.Amount.ShouldEqual(paymentAmount);
            stay.Payment.BillingDate.ShouldEqual(paymentBillingDate);
            stay.Payment.CheckNumber.ShouldEqual(paymentCheckNumber);
            stay.Payment.Method.ShouldEqual(paymentMethod);
            stay.Payment.ReceivedDate.ShouldEqual(paymentReceivedDateTime);
            stay.Payment.Type.ShouldEqual(paymentType);            
        }
    }
}
